import 'package:flutter/widgets.dart';
import '../../../../lib_basemodel/chat_room/chat/hb_rtm_message_type.dart';
import '../../msg/room_msg.dart';
import 'item_builder/room_gift_msg_item_buider.dart';
import 'item_builder/room_msg_item_builder.dart';
import 'item_builder/room_text_msg_item_builder.dart';

/// 公屏消息Item widget
class RoomMsgItem extends StatelessWidget {
  final RoomMsg msg;
  const RoomMsgItem({Key? key, required this.msg}) : super(key: key);

  RoomMsgItemBuilder? get itemBuilder {
    switch (msg.rtmMsg?.rtmType) {
      case HBRtmMessageType.rtmSmallMessageTypeText:
      case HBRtmMessageType.rtmSmallMessageTypeUserJoin:
        return RoomTextMsgItemBuilder();
      case HBRtmMessageType.rtmSmallMessageTypeReward:
        return RoomGiftMsgItemBuider();
      default:
        return null;
    }
  }

  @override
  Widget build(BuildContext context) {
    if (itemBuilder != null) {
      return itemBuilder!.buildItem(context, msg);
    } else {
      return Container();
    }
  }
}
